import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter2 } from '@/utils/formatTime'
import * as LevelApi from '@/api/member/level'

// 表单校验
export const rules = reactive({
  spuId: [required],
  name: [required],
  status: [required],
  pointAndPricePickupTime:[required],
  pointPickupTime:[required],
  startTime: [required],
  endTime: [required],
  totalStock: [required],
  price: [required],
  point:[required],
  inviteNum:[required],
  memberLevel: [required]
})

// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    label: '提货名称',
    field: 'name',
    isSearch: true,
    form: {
      colProps: {
        span: 24
      }
    },
    table: {
      width: 120
    }
  },

  {
    label: '提货状态',
    field: 'status',
    dictType: DICT_TYPE.COMMON_STATUS,
    dictClass: 'number',
    isSearch: true,
    isDetail: true,
    form: {
      colProps: {
        span: 24
      },
      component: 'Radio',
    },
    table: {
      width: 120
    }
  },
  {
    label: '提货开始时间',
    field: 'startTime',
    formatter: dateFormatter2,
    isSearch: true,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD',
        type: 'daterange'
      }
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'date',
        valueFormat: 'x'
      }
    },
    table: {
      width: 120
    }
  },
  {
    label: '提货结束时间',
    field: 'endTime',
    formatter: dateFormatter2,
    isSearch: true,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD',
        type: 'daterange'
      }
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'date',
        valueFormat: 'x'
      }
    },
    table: {
      width: 120
    }
  },
  {
    label: '提货积分',
    field: 'point',
    form: {
      component: 'InputNumber',
      value: 1
    },
    table: {
      width: 120
    }
  },
  {
    label: '提货价格',
    field: 'price',
    form: {
      component: 'InputNumber',
      value: 1
    },
    table: {
      width: 120
    }
  },
  {
    label: '提货总库存',
    field: 'totalStock',
    form: {
      component: 'InputNumber',
      value: 0
    },
    table: {
      width: 120
    }
  },
 {
    label: '邀请人数',
    field: 'inviteNum',
    form: {
      component: 'InputNumber',
      value: 0
    },
    table: {
      width: 120
    }
  },
  {
    label: '纯积分提货次数',
    field: 'pointPickupTime',
    form: {
      component: 'InputNumber',
      value: 0
    },
    table: {
      width: 120
    }
  },
  {
    label: '积分+现金提货次数',
    field: 'pointAndPricePickupTime',
    form: {
      component: 'InputNumber',
      value: 0
    },
    table: {
      width: 120
    }
  },
   {
    label: '用户等级',
    field: 'memberLevel',
    form: {
      component: 'Select',
      componentProps: {
        multiple: false,
        optionsAlias: {
          labelField: 'name',
          valueField: 'id'
        }
      },
      api: LevelApi.getSimpleLevelList
    },
    table: {
      width: 300
    }
  },
  {
    label: '活动商品',
    field: 'products',
    isTable: true,
    isSearch: false,
    form: {
      colProps: {
        span: 24
      }
    },
    table: {
      width: 300
    }
  },
  {
    label: '提货活动描述',
    field: 'description',
    isSearch: false,
    form: {
      component: 'Input',
      componentProps: {
        type: 'textarea',
        rows: 4
      },
      colProps: {
        span: 24
      }
    },
    table: {
      width: 300
    }
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
